package com.maoxx.stuchoosemssbv_service.service;

import com.maoxx.stuchoosemssbv_service.entity.CourseTeacherInfo;
import com.maoxx.stuchoosemssbv_service.entity.SCTInfo;
import com.maoxx.stuchoosemssbv_service.entity.StudentCourseTeacher;
import com.maoxx.stuchoosemssbv_service.mapper.SCTMapper;
import com.maoxx.stuchoosemssbv_service.mapper.StudentCourseTeacherMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @className: SCTService
 * @author: Maoxx
 * @date: 2024/11/4 23:01
 * @Version: 1.0
 * @description:
 */

@Service
public class SCTService {

    @Autowired
    private StudentCourseTeacherMapper studentCourseTeacherMapper;

    @Autowired
    private SCTMapper sctMapper;



    public boolean isSCTExist(StudentCourseTeacher studentCourseTeacher) {
        return studentCourseTeacherMapper.findBySCT(studentCourseTeacher).size() != 0;
    }

    public boolean save(StudentCourseTeacher studentCourseTeacher) {
        return studentCourseTeacherMapper.insert(studentCourseTeacher);
    }

    public List<SCTInfo> getSCTInfo() {
        return sctMapper.getSCTInfo();
    }

    public SCTInfo findByIdWithTerm(Integer sid, Integer cid, Integer tid, String term) {
        return sctMapper.findBySearch(
                sid, null, 0,
                cid, null, 0,
                tid, null, 0,
                null, null, term).get(0);
    }

    public boolean updateById(Integer sid, Integer cid, Integer tid, String term, Integer grade) {
        return sctMapper.updateById(sid, cid, tid, term, grade);
    }

    public boolean deleteById(Integer sid, Integer cid, Integer tid, String term) {
        StudentCourseTeacher studentCourseTeacher = new StudentCourseTeacher();
        studentCourseTeacher.setSid(sid);
        studentCourseTeacher.setCid(cid);
        studentCourseTeacher.setTid(tid);
        studentCourseTeacher.setTerm(term);
        return sctMapper.deleteBySCT(studentCourseTeacher);
    }

    public List<CourseTeacherInfo> findBySid(Integer sid, String term) {
        return sctMapper.findByStudentId(sid, term);
    }

    public List<String> findAllTerm() {
        return sctMapper.findAllTerm();
    }
}
